% 布朗桥 SDE （随机微分方程），可以生成一条连接始末点的随机连线
% Gitee Repo

clc
clear

dx = 0.01;
x0 = 0;
y0 = 0;
x1 = 4;
y1 = 7;

f = @(x,y) (y1 - y)/(x1 - x);

y(1)=x0;
x(1)=y0;

for i = 1:ceil(x1/dx)
  y(i+1) = y(i) + f(x(i), y(i))*dx + randn()*sqrt(dx);
  x(i+1) = x(i) + dx;
end

figure()
hold on
axis equal

plot(x,y);
scatter(x0,y0);
scatter(x1,y1);

